package com.bestcem.xm.member.mq.receiver.biz.kafka;


import com.bestcem.xm.member.mq.message.*;
import com.bestcem.xm.member.mq.receiver.biz.MemberConsumers;
import com.bestcem.xm.member.mq.receiver.biz.ReceiverService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.stereotype.Component;

import java.util.function.Consumer;

@Slf4j
@Component
@ConditionalOnProperty(prefix = "application", name = "mqType", havingValue = "kafka")
public class KafkaConsumers implements MemberConsumers {

    private ReceiverService receiverService;

    @Autowired
    public void setReceiverService(ReceiverService receiverService) {
        this.receiverService = receiverService;
    }

    /**
     * 分组规则修改
     */
    @Bean
    @Override
    public Consumer<GenericMessage<GroupingMessage>> groupConditionMod() {
        return msg -> receiverService.groupConditionMod(msg);
    }

    /**
     * 联系人删除
     */
    @Bean
    @Override
    public Consumer<GenericMessage<GroupDeletedMessage>> groupDeleted() {
        return msg -> receiverService.groupDeleted(msg);
    }

    /**
     * 创建用户
     */
    @Bean
    @Override
    public Consumer<GenericMessage<UserMessage>> userCreated() {
        return msg -> receiverService.userCreated(msg);
    }

    /**
     * 更新用户同步更新内部联系人
     */
    @Bean
    @Override
    public Consumer<GenericMessage<UserMessage>> userUpdated() {
        return msg -> receiverService.userUpdated(msg);
    }

    /**
     * 机构创建
     */
    @Bean
    @Override
    public Consumer<GenericMessage<OrgCreatedMessage>> orgCreated() {
        return msg -> receiverService.orgCreated(msg);
    }

    /**
     * 保存联系人足迹
     */
    @Bean
    @Override
    public Consumer<GenericMessage<FootprintMessage>> footprintSave() {
        return msg -> receiverService.footprintSave(msg);
    }

    /**
     * 联系人创建、联系人更新-调度至分组
     */
    @Bean
    @Override
    public Consumer<GenericMessage<MemberCreationUpdMessage>> memberCreationUpd() {
        return msg -> receiverService.memberCreationUpd(msg);
    }

    /**
     * 联系人本地缓存
     */
    @Bean
    @Override
    public Consumer<GenericMessage<SourceCardMessage>> memberDb() {
        return msg -> receiverService.memberDb(msg);
    }

    /**
     * 删除联系人
     */
    @Bean
    @Override
    public Consumer<GenericMessage<MemberDeletedMessage>> memberDeleted() {
        return msg -> receiverService.memberDeleted(msg);
    }

    /**
     * 打标签消息
     */
    @Bean
    @Override
    public Consumer<GenericMessage<MemberSliceMessage>> memberSlice() {
        return msg -> receiverService.memberMemberSlice(msg);
    }

    /**
     * 同步所有已授权的公众号粉丝数据 延时队列
     */
    @Bean
    @Override
    public Consumer<GenericMessage<WechatMemberSyncMessage>> wechatMemberScheduleSyncDelay() {
        return msg -> receiverService.wechatMemberScheduleSyncDelay(msg);
    }

    /**
     * 同步微信粉丝
     */
    @Bean
    @Override
    public Consumer<GenericMessage<WechatMemberSyncMessage>> memberWechatMemberSchedule() {
        return msg -> receiverService.memberWechatMemberSchedule(msg);
    }

    /**
     * 微信同步联系人(调度) 延迟队列
     */
    @Bean
    @Override
    public Consumer<GenericMessage<WechatMemberSyncMessage>> wechatMemberSyncDelayDelay() {
        return msg -> receiverService.wechatMemberSyncDelayDelay(msg);
    }

    /**
     * 处理微信公众号粉丝同步联系人
     */
    @Bean
    @Override
    public Consumer<GenericMessage<WechatMemberSyncMessage>> memberWechatMemberSync() {
        return msg -> receiverService.wechatMemberSyncDelay(msg);
    }

    /**
     * 答卷提交
     */
    @Bean
    @Override
    public Consumer<GenericMessage<RespondentDataMessage>> surveyRespondentSubmit() {
        return msg -> receiverService.surveyRespondentSubmit(msg);
    }

    /**
     * 答卷时授权获取微信账号信息
     */
    @Bean
    @Override
    public Consumer<GenericMessage<SyncWechatAccountInfoMessage>> syncWechatAccountInfo() {
        return msg -> receiverService.syncWechatAccountInfo(msg);
    }

    /**
     * 监听用户层级变动
     */
    @Bean
    @Override
    public Consumer<GenericMessage<SyncMemberStoreMessage>> userGroupChanged() {
        return msg -> receiverService.userGroupChanged(msg);
    }

    /**
     * 微信公众号授权
     */
    @Bean
    @Override
    public Consumer<GenericMessage<WechatOfficialAccountGrantedMessage>> wechatOfficialAccountGranted() {
        return msg -> receiverService.wechatOfficialAccountGranted(msg);
    }

    /**
     * 监听联系人延迟队列消息/group member 重新分组
     */
    @Bean
    @Override
    public Consumer<GenericMessage<MemberCreationUpdMessage>> memberRegroupMember() {
        return msg -> receiverService.memberRegroupMember(msg);
    }

    /**
     * 监听联系人延迟队列消息/group members 重新分组
     */
    @Bean
    @Override
    public Consumer<GenericMessage<GroupingMessage>> memberRegroupMembers() {
        return msg -> receiverService.memberRegroupMembers(msg);
    }

    /**
     * 微信公众号同步打开与关闭延迟队列消息
     */
    @Bean
    @Override
    public Consumer<GenericMessage<WechatMemberSyncMessage>> wechatMemberSyncDelay() {
        return msg -> receiverService.wechatMemberSyncDelay(msg);
    }

}